package com.itgungnir.diyshuo.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itgungnir.diyshuo.activity.R;
import com.itgungnir.diyshuo.bean.GoodsBean;

import java.util.List;

/**
 * Created by My on 2016/10/6.
 */

public class DanPinAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsBean> list;

    public DanPinAdapter(Context context, List<GoodsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    ViewHolder holder=null;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            LayoutInflater inflater=LayoutInflater.from(context);
            convertView=inflater.inflate(R.layout.item_danpin,null);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.danpin_iv);
            holder.tv_subject= (TextView) convertView.findViewById(R.id.danpin_title);
            holder.tv_price= (TextView) convertView.findViewById(R.id.danpin_price);
            holder.tv_views= (TextView) convertView.findViewById(R.id.danpin_love);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(Uri.parse(list.get(position).getCoverpath())).into(holder.iv);
        holder.tv_subject.setText(list.get(position).getSubject());
        holder.tv_price.setText("￥"+list.get(position).getPrice());
        holder.tv_views.setText(list.get(position).getViews());
        return convertView;
    }
    static class ViewHolder{
        ImageView iv;
        TextView tv_subject,tv_price,tv_views;
    }
}
